package com.group9.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group9.dto.FruitInfosPageParams;
import com.group9.dto.FruitInfosParams;
import com.group9.mapper.FruitInfosMapper;
import com.group9.pojo.FruitInfo;
import com.group9.service.FruitInfosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by QZP on 2020/5/11.
 */

@Service
//Spring 框架在扫描的时候，会创建其实例存入到IoC容器中
public class FruitInfosServiceImpl implements FruitInfosService {

    @Autowired
    FruitInfosMapper fruitInfosMapper;



    @Override
    public List<FruitInfo> selectAll() {
        List<FruitInfo> fruitInfos = fruitInfosMapper.selectAll();
        return  fruitInfos;
    }

    @Override
    public FruitInfosPageParams<FruitInfo> selectByPages(FruitInfosPageParams fruitInfosPageParams) {
        PageHelper.startPage(fruitInfosPageParams.getCurrPage(),fruitInfosPageParams.getPageSize());
        PageInfo<FruitInfo> pageInfo = new PageInfo<>();
        List<FruitInfo> fruitInfos = pageInfo.getList();
        fruitInfosPageParams.setTotalSize(pageInfo.getTotal());
        fruitInfosPageParams.setFruitInfosList(fruitInfos);
        return null;
    }


    @Override
    public int selectCountSize() {
        int totalSize = fruitInfosMapper.selectCountSize();
        return totalSize;
    }

    @Override
    public List<FruitInfo> selectByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<FruitInfo> fruitInfos = fruitInfosMapper.selectAll();
        return fruitInfos;
    }

    @Override
    public List<FruitInfo> selectByNameAndKind(FruitInfosParams fruitInfosParams) {
        List<FruitInfo> fruitInfos = fruitInfosMapper.selectByNameAndKind(fruitInfosParams);
        return fruitInfos;
    }

}
